#include "ObjectStomper/ObjectStomperGUI.h"
#include "StompedReality/Core/FileSystem.h"
#include "StompedReality/Core/IGame.h"
#include "StomperLib/Controls/EditorObjectTree.h"
#include "StomperLib/Elements/FileSelection.h"
#include "StomperLib/Objects/PatchCollector.h"
namespace ObjectStomper {
ObjectStomperGUI::ObjectStomperGUI ( Gwen::Controls::Canvas* canvas ) :
  StomperLib::BaseLayout( canvas )
{
  this->Model = new StomperLib::ToolModel( this ); // this );
}

ObjectStomperGUI::~ObjectStomperGUI ( )
{

}

void ObjectStomperGUI::OnCreateBaseElements( )
{

  auto patchCollector = new StomperLib::PatchCollector( );

  auto objectTree = new StomperLib::Controls::EditorObjectTree( this, "objectTree" );
  objectTree->SetGame( this->m_Game );
  objectTree->AddCollector( patchCollector );
  objectTree->SetBounds( 100, 100, 200, 300 );
  objectTree->SetAddGlobalSelection( true );

  this->onOpenProject.Add( this, &ObjectStomperGUI::OnOpenProject );

  this->onOpenProject.Add( objectTree, &StomperLib::Controls::EditorObjectTree::CollectItems );
}

void ObjectStomperGUI::OnOpenProject( Gwen::Event::Info info )
{
  int p = info.String.Get( ).find_last_of( FILE_SEPARATORE );
  this->m_Game->getFileSystem( )->setBasePath( info.String.Get( ).substr( 0, p ));
  this->Model->ProjectFile = info.String.Get( );
}

}
